home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Dev / misc / temgen.lha / Temgen / tg-0.11 / debug.c < prev    next >
C/C++ Source or Header  |  2002-12-18  |  1KB  |  66 lines

  1. #include "atom.h"
  2. #include "debug.h"
  3. #include "sysdefs.h"
  4.  
  5. /* debugger modes */
  6. #define      DM_NEXT        0
  7. #define      DM_STEP        1
  8. #define      DM_RUN         2
  9.  
  10. static int deb_mode = DM_NEXT;
  11.  
  12. char *debugp( const char *fmt, ... )
  13. {
  14.     static char cmd[ 512 ];
  15.     char newcmd[ 512 ];
  16.     va_list ap;
  17.    
  18.     if ( !debugger ) return NULL; 
  19.     va_start( ap, fmt );
  20.     vprintf( fmt, ap );
  21.     va_end( ap );
  22.     fgets( newcmd, sizeof(newcmd), stdin );
  23.     if ( newcmd[0] != '\n' ) 
  24.         strncpy( cmd, newcmd, sizeof(cmd) );
  25.     
  26.     cmd[ sizeof(cmd)-1 ] = '\0';
  27.     return cmd;
  28. }
  29.  
  30. static const char *prn_fname( struct sourcefile *sf )
  31. {
  32.         return atom_name( sf->fname );
  33. }
  34.  
  35. static const char *prn_command( int index, struct command *c, 
  36.         struct sourcefile *sf )
  37. {
  38.     static char buf[ 512 ];
  39.     
  40.     snprintf( buf, sizeof(buf), "%s:%d: %s", 
  41.                     prn_fname(sf), index, tt_find( sf->tt, index ) );
  42.     return buf;
  43. }
  44.  
  45. void  deb_cmd( int index, struct command *c, struct sourcefile *sf )
  46. {
  47.     char *cmd;
  48.     
  49.     switch( deb_mode ) {
  50.         case DM_RUN: 
  51.             return;
  52.         default:
  53.             cmd = debugp( "%s(tg) ", prn_command( index, c, sf ) );
  54.     }
  55. }
  56.  
  57. void  debout( const char *fmt, ... )
  58. {
  59.     va_list ap;
  60.    
  61.     if ( !debugger ) return; 
  62.     va_start( ap, fmt );
  63.     vprintf( fmt, ap );
  64.     va_end( ap );
  65. }
  66.